<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>回收专区</title>
    <link rel="stylesheet" type="text/css" href="../../../../css/aui/aui.css" />
    <style>
        #header {
            display: flex;
            align-items: center;
            background: #F5F5F5;
            padding: .75rem 0;
            justify-content: space-around;
        }

        #header div {
            text-align: center;
        }

        #header div span {
            margin-right: .3rem;
        }

        .triangle {
            padding: 0;
            display: inline-block;
            width: 0;
            height: 0;
            border-right: 0.35rem solid transparent;
            border-left: 0.35rem solid transparent;
            border-top: 0.35rem solid black;
        }

        .aui-list {
            background-image: none;
        }

        .aui-list .aui-list-item .aui-list-item-media img {
            /*border: 1px solid #ECECEC;*/
            /*border-radius: 100%;*/
            width: 3.5rem;
            height: 3.5rem;
        }

        .aui-list .aui-list-item {
            background-image: -webkit-linear-gradient(90deg, #F0F0F0, #F0F0F0 50%, transparent 50%);
            padding: 0.5rem 0 0.5rem 0.75rem;
        }

        .aui-list .aui-list-item .list_info {
            display: flex;
        }

        .aui-list .aui-list-item .list_info .list_text {
            display: flex;
            flex-direction: column;
            width: 100%;
            height: 100%;
            justify-content: space-between;
            align-items: flex-start;
            border-right: 1px solid #F0F0F0;
            margin-right: .75rem;
        }

        .aui-list .aui-list-item .list_info img {
            width: 2.5rem;
        }
    </style>
</head>

<body>
    <div id="app">
        <div id="header">
            <div class="area" @click="openCity()"><span>{{userRegion.area}}</span><span class="triangle"></span></div>
        </div>
        <div class="aui-content">
            <ul class="aui-list aui-media-list">
                <li class="aui-list-item" v-for='v in list' @click="detail(v.recycle_id)">
                    <div class="aui-media-list-item-inner">
                        <div class="aui-list-item-media">
                            <img :src="v.cover_imgurl">
                        </div>
                        <div class="aui-list-item-inner list_info">
                            <div class="list_text">
                                <div>{{v.title}}</div>
                                <p>{{v.region}}</p>
                            </div>
                            <div>
                                <img src="../../../../image/icon/dianhua.png" alt="" @click.stop="call(v.contact_phone)">
                            </div>
                        </div>

                    </div>
                </li>
            </ul>
        </div>
    </div>
</body>
<script src="../../../../script/api.js" charset="utf-8"></script>
<script src="../../../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../../../script/common/common.js" charset="utf-8"></script>
<script src="../../../../script/common/config.js" charset="utf-8"></script>
<script src="../../../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    var stateBarH = '';
    apiready = function() {
        api.parseTapmode();

        //沉浸式状态栏
        var systemType = api.systemType;
        var statusBar = api.require('statusBar');
        if (systemType == "ios") {
            if (navigator.userAgent.indexOf("iPhone") != -1) {
                stateBarH = api.safeArea.top;
            }
        } else {
            statusBar.getStatusBarHeight(function(ret, err) {
                stateBarH = ret.statusHeight;
            });
        }

        vm.init();
    }

    var vm = new Vue({
        el: "#app",
        data: {
            list: [],
            userRegion: {},
            pages: 1,
            title: ''
        },
        methods: {
            init() {
                this.userRegion = get_local('user_region');
                this.page();
                this.getListData();
            },
            getListData() {
                var self = this;
                _ajax(Config.api.RecycleHuishou, {
                    region_areaid: self.userRegion.areaid,
                    title: self.title,
                    pages: self.pages
                }, function(res) {
                    if (res.code === 200) {
                        if (res.data.length === 0) {
                            $toast('数据已加载完毕');
                            self.pages = -1;
                        } else {
                            self.list = self.list.concat(res.data);
                        }
                    }
                })
            },
            page() {
                // 下拉刷新
                var self = this;
                push_down(function() {
                    //下拉刷新恢复
                    push_down_over();

                    self.pages = 1;
                    self.list = [];
                    self.getListData();
                });

                //上拉加载
                push_up(function() {
                    if (self.pages === -1) {
                        $toast('数据已加载完毕');
                    } else {
                        ++self.pages;
                        self.getListData();
                    }
                });
            },
            openCity() {
                api.openFrame({
                    name: 'mask',
                    url: '../../../city/city_win.html',
                    rect: {
                        x: 0,
                        y: stateBarH,
                        w: 'auto',
                        h: 'auto'
                    },
                    bgColor: 'rgba(0,0,0,0.5)',
                    pageParam: {
                        name: api.winName,
                        frameName: api.frameName,
                        provinceid: this.userRegion.provinceid,
                        cityid: this.userRegion.cityid,
                        areaid: this.userRegion.areaid,
                    }
                });
            },
            detail(id) {
                open_w('recycle_detail_win', './recycle_detail_win.html', {
                    id: id
                });
            },
            call(phone) {
                api.call({
                    type: 'tel_prompt',
                    number: phone
                });
            }
        }
    });

    function setCity(province, city, area) {
        var data = {
            "provinceid": province.code,
            "province": province.name,
            "cityid": city.code,
            "city": city.name,
            "areaid": area.code,
            "area": area.name
        };

        vm.userRegion = data;
        vm.pages = 1;
        vm.list = [];
        vm.getListData();
    }

    function search(cont) {
        vm.title = cont;
        vm.pages = 1;
        vm.list = [];
        vm.getListData();
    }
</script>

</html>
